package com.since.data_structure;

import java.util.HashMap;

public class DataStructures {
    public static void main(String[] args) {
        final ThreadLocal<String> localName = new ThreadLocal();
        final HashMap<Integer, String> map = new HashMap<>(2);
        new Thread("线程1") {
            @Override
            public void run() {
                localName.set("Sincerity");
                String s = localName.get();
                System.out.println(Thread.currentThread().getName() + "获取到ThreadLocal值=" + s + "---ThreadLocal---" + localName);
                map.put(0, Thread.currentThread().getName());
                System.out.println(Thread.currentThread().getName() + "获取到map的长度" + map.size());

            }
        }.start();
        String s = localName.get();
        System.out.println("主线程获取到ThreadLocal值=" + s);
        new Thread("线程2") {
            @Override
            public void run() {
                localName.set("Sincerity222");
                String s = localName.get();
                System.out.println(Thread.currentThread().getName() + "获取到ThreadLocal值=" + s + "---ThreadLocal---" + localName);
                System.out.println(Thread.currentThread().getName() + "获取到map的长度" + map.size());
            }
        }.start();
        String s2 = localName.get();
        System.out.println("主线程获取到ThreadLocal值=" + s2);
    }
}
